<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="设备地址" prop="deviceId">
        <el-select
                v-model="queryParams.device"
                placeholder="请选择"
                style="width: 14vw; height: 30px"
                @change="change"
              >
                <el-option
                  v-for="item in deviceList"
                  :key="item.imei"
                  :label="item.regionName"
                  :value="item.imei"
                 
                >
                </el-option>
              </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
  

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="postList">
      <el-table-column label="序号" align="center" type="index" />
      <el-table-column label="设备编号" align="center" prop="device" />
      <el-table-column label="气体名称" align="center" prop="gasname1" />
      <el-table-column label="气体值" align="center" prop="gasvalue1" />
      <el-table-column label="气体名称" align="center" prop="gasname2" />
      <el-table-column label="气体值" align="center" prop="gasvalue2" />
      <!-- <el-table-column label="报警值" align="center" prop="alarm" >
        <template slot-scope="scope">
          <el-tag type="danger">{{scope.row.alarm}}</el-tag>
        </template>
      </el-table-column> -->
      <el-table-column label="时间" align="center" prop="time" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList3"
    />

    
  </div>
</template>

<script>
// import {listGashistory} from "@/api/gas/list";
import {listGas,getHistory} from "@/api/gas/list";
export default {
  name: "Histroy",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      deviceList: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 岗位选项
      postOptions: [],
      // 弹出层标题
      title: "",
      imageUrl:'',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        device:undefined,
      },
      // 表单参数
      form: {},
      timer:{
        time:undefined
      }
      // 表单校验
 
    };
  },
  created() {
    this.getList2();
    setTimeout(() => {
      this.getList();
    }, 1000);
  
 
  },
  methods: {
      /** 查询岗位列表 */
      getList2() {
      this.loading = true;
      listGas().then((response) => {
        console.log("response,responseresponse", this.deviceList);
        this.deviceList = response.rows;
        console.log("response,responseresponse", this.deviceList);
        this.queryParams.device = response.rows[0].imei
      });
    },
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
   
      getHistory(this.queryParams).then(response => {
        console.log('response,responseresponse',response);
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
       /** 查询岗位列表 */
       getList3() {
      this.loading = true;
      // this.queryParams.deviceId = this.deviceList[0].id
      getHistory(this.queryParams).then(response => {
        console.log('response,responseresponse',response);
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.$refs.upload.clearFiles();
    },
    handleRecord:function(row){
    const id = {
      id:row.id,
      isread:1
    }
    listAlarmRecordNow(id).then(response => {
        this.$modal.msgSuccess("已读成功");
        this.getList()
      })
    },
    // 表单重置
    reset() {
      this.form = {
        picture: undefined,
        name: undefined,
      };
      this.imageUrl = "";
      this.resetForm("form");
    },
    change(){
      this.queryParams.pageNum = 1;
      this.getList3();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList3();
    },
    dateFormat(picker){
                    this.queryParams.startTime=picker[0]
                    this.queryParams.endTime=picker[1]
                },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.timer = {}
      this.queryParams={
        pageNum: 1,
        pageSize: 10,
        deviceId:undefined,
        // alarmType: undefined,
        startTime:undefined,
        endTime:undefined
      }
      this.handleQuery();
    },

  }
};
</script>
